#ifndef T_SETPARAMS_H
#define T_SETPARAMS_H

#include "ElaScrollPage.h"
#include <QButtonGroup>
#include "src/common.h"

class ElaScrollPageArea;
class ElaComboBox;
class ElaLineEdit;
class ElaRadioButton;

#define T_SetParamsIns T_SetParams::Instance()

class T_SetParams : public ElaScrollPage
{
    Q_OBJECT
public:
    explicit T_SetParams(QWidget* parent = nullptr);
    ~T_SetParams() override;

    static T_SetParams *Instance();

    enum LayoutBlock {
        LW = 0,
        LH,
        HW,
        WL,
        WH,
        HL
    };

    enum LayoutGroup {
        HX = 0,
        ZX,
        DHDL,
    };

    enum RowOrCol {
        ROW = 0,
        COL
    };

public:
    void setAllowCreate(bool is_allow_create);

private:
    void initUI();
    void initArea();
    void createItem();
    void createOneGroup();
    void createBlockItem();
    bool judgeGroup();
    void calcCommon(double & blockSumWidth, double &blockSumHeight, int sum);
    void calcModelGroupCount();
    bool judgeSplit(double blockSumWidth,double blockSumHeight);
    void calc();
    void calcResult();
    void importExcel(const QString &excel_path);

private slots:
    void on_currentTextChanged(const QString & text);
    void on_importExcelBtnClicked();
    void on_volLeEditFinished();
    void on_ahLeEditFinished();
    void on_rowLeEditFinished();
    void on_hvddButtonGroupToggled(QAbstractButton *button, bool isToggled);
    void on_lwhlButtonGroupToggled(QAbstractButton *button, bool isToggled);
    void on_hzjButtonGroupToggled(QAbstractButton *button, bool isToggled);
    void on_xyzButtonGroupToggled(QAbstractButton *button, bool isToggled);
    void on_rcButtonGroupToggled(QAbstractButton *button, bool isToggled);
    void on_calcNumBtnClicked();

signals:
    void flushBlockInfo();
    void flushPackInfo(int c_num,int sum_num,int group_num);
    void addMainRect(const cutomitem &data,qreal leftMar,qreal topMar,qreal rightMar,qreal bottomMar);
    void addMainRect1(const cutomitem &data,qreal leftMar,qreal topMar,qreal rightMar,qreal bottomMar);
    void addBlockRect(const cutomitem& data,double space,int num,int direction);
    void addBlockRect1(const cutomitem& data,double space,int num,int direction);
    void addSubRect(const cutomitem& data);
    void clearScene();
    void cchildItemSpaceSignal(const QStringList &list,double hSpace,double vSpace,const QString &hLayout,const QString &vLayout);
    void addOuterRect_paintLine(const QStringList &tmpList);
    void addOuterRect_paintLine1(const QStringList &tmpList);

private:
    ElaLineEdit *m_totalWLe{nullptr};
    ElaLineEdit *m_totalHLe{nullptr};
    ElaLineEdit *m_totalHDLe{nullptr};
    ElaLineEdit *m_blockVolValueLe{nullptr};
    ElaLineEdit *m_blockAhValueLe{nullptr};
    ElaLineEdit *m_setRowCol{nullptr};

    ElaScrollPageArea *m_blockInfoArea{nullptr};
    ElaComboBox *m_combobox{nullptr};
    ElaRadioButton *m_hButton{nullptr};
    ElaRadioButton *m_vButton{nullptr};
    ElaRadioButton *m_ddButton{nullptr};
    ElaRadioButton *m_lwButton{nullptr};
    ElaRadioButton *m_lhButton{nullptr};
    ElaRadioButton *m_hwButton{nullptr};
    ElaRadioButton *m_wlButton{nullptr};
    ElaRadioButton *m_whButton{nullptr};
    ElaRadioButton *m_hlButton{nullptr};
    ElaRadioButton *m_xButton{nullptr};
    ElaRadioButton *m_yButton{nullptr};
    ElaRadioButton *m_zButton{nullptr};
    ElaRadioButton *m_rowButton{nullptr};
    ElaRadioButton *m_colButton{nullptr};

    QButtonGroup* m_hvddButtonGroup{nullptr};
    QButtonGroup* m_lwhlButtonGroup{nullptr};
    QButtonGroup* m_hzjButtonGroup{nullptr};
    QButtonGroup* m_xyzButtonGroup{nullptr};
    QButtonGroup* m_rcButtonGroup{nullptr};

    int m_direction{0};
    LayoutBlock m_layout{LW};
    LayoutGroup m_layout_group{HX};

    double m_duan_value_H;
    double m_duan_value_V;
    double m_sum_block_dh;
    double m_single_w;
    double m_single_h;

    QStringList m_list_groups;

    int m_c_num{0}; //串数
    int m_b_num{0}; //并数
    int m_blockSingNum{0}; //单模组电芯数量
    int m_onePNum{0};   //1P的电芯数量
    int m_blockSumNum{0};     //电芯总数
    int m_groupNum{0};  //模组数量


    int m_row_max;  //group最多行
    int m_col_max;  //group最多列

    int m_set_row_max{0};  //group设置行
    int m_set_col_max{0};  //group设置列

    int m_pack_count_max{0};
    int m_splitInt{1};

    bool m_is_import_excel{false};
    bool m_is_allow_create{false};
    bool m_main_is_swap{false};

    RowOrCol m_row_or_col{ROW};
    int m_one_row_or_col_num{0};  //每行或者每列的电芯数量

};

#endif // T_SETPARAMS_H
